In [1]:
debugDict = {
    'ModSchema': ['QAM','QAM','PSK','PSK'],
    'pulseShaping': ['rrc','square','rrc','square'],
    'txAmp': [40,40,40,40],
    'rxAmp': [20,20,20,20],
    'BER': [0.495,0.59,0.45,0.5545]
}
In [11]:
def plotBaseBandData(data,symbol,rxSymbol=[]):
    colors = np.zeros(len(data))
    if len(rxSymbol)>0:
        figure, axis = ploot.subplots(1, 2)
        for i in range(len(rxSymbol)):
            colors[i] = rxSymbol[i]/4
        axis[1].scatter(data.real,data.imag,c=colors)
        for i in range(len(symbol)):
            colors[i] = symbol[i]/4
        axis[0].scatter(data.real,data.imag,c=colors)
        ploot.show()
    else:
        for i in range(len(symbol)):
            colors[i] = symbol[i]/4
        ploot.scatter(data.real,data.imag,c=colors)
def Convolve(data1,data2):
    ans = np.zeros(len(data1),dtype=type(data1[0]))
    for i in range(0,len(data1)):
        for j in range(0,len(data2)):
            if i-j >=0:
                ans[i] = ans[i] + data1[i-j]*data2[j]
    return ans
def getSNRvsBER(snrMin,snrMax,step):
    snr = np.linspace(snrMin,snrMax,step)
    ber = np.zeros(len(snr))
    for i in range(len(snr)):
        rxAmpDB = 20
        pbRx = np.convolve(pb,ir,mode = 'same')
        pbRx = comm.awgn(pbRx,snr[i])
        pbRx = pbRx * (10**(rxAmpDB//20))
        bbRx = comm.downconvert(pbRx, int(samplingRate/symbolRate),carrierFreq,samplingRate)
        rxSymbols = comm.demodulate(bbRx,psk)
        ber[i] = comm.ber(comm.sym2bi(rxSymbols,m),comm.sym2bi(symbols,m))
    fig, ax = ploot.subplots(1, 1, figsize=(4, 4), layout='constrained')
    ax.set_xlabel('SNR')
    ax.set_ylabel('BER')
    ax.set_ylim(0,1)
    ax.set_xscale('log')
    ax.plot(snr,ber,'x',ls='-')
    return
def getBeamPattern(dictofDegree):
    ptrn = np.zeros((37,2))
    for i in range(len(ptrn)):
        ptrn[i][0] = -180 + i*10
        try:
            ptrn[i][1] = dictofDegree[-180 + i*10]
        except:
            ptrn[i][1] = 0
    return ptrn
def plotDiffData(rx_range_min,rx_range_max,samples):
    rx_range = np.linspace(rx_range_min,rx_range_max,samples)
    for i in rx_range:
        env = pm.create_env2d(frequency=27000,tx_depth=250,rx_depth=30,depth=1000,rx_range=i,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
        arrivals = pm.compute_arrivals(env)
        ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
        pbRx = np.convolve(pb,abs(ir)[0:int(0.1*100000)])
        pbRx = pbRx[:len(pb)]
        pbRx = comm.awgn(pbRx,20)
        pbRx = pbRx * (10**(rxAmpDB//20))
        bbRx = comm.downconvert(pbRx, int(samplingRate/symbolRate),carrierFreq,samplingRate)
        rxSymbols = comm.demodulate(bbRx,psk)
        print("Range: " + str(i))
        print(comm.ber(comm.sym2bi(rxSymbols,m),comm.sym2bi(symbols,m)))
        plotBaseBandData(bbRx,symbols,rxSymbol=rxSymbols)
In [3]:
import arlpy.uwapm as pm
import arlpy.comms as comm
import arlpy.plot as plt
import arlpy.signal as signal
import numpy as np
from scipy.fft import fft, fftfreq
import matplotlib.pyplot as ploot
import math
import matplotlib.axes as axes
In [4]:
pm.models()
rx_range = 2000
tx_depth = 500
rx_depth = 450
print(np.rad2deg(np.arctan((tx_depth-rx_depth)/rx_range)))
env = pm.create_env2d(frequency=27000,tx_depth=tx_depth,rx_depth=rx_depth,depth=1000,rx_range=rx_range,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
arrivals = pm.compute_arrivals(env)
ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
pm.print_env(env)
plt.plot(abs(ir)[0:int(0.1*100000)],fs = 100000)
1.4320961841646465
                name : arlpy
   bottom_absorption : 0.1
      bottom_density : 1600
    bottom_roughness : 0
   bottom_soundspeed : 1600
               depth : 1000
        depth_interp : linear
           frequency : 27000
           max_angle : 80
           min_angle : -80
              nbeams : 0
            rx_depth : 450
            rx_range : 2000
          soundspeed : 1500
   soundspeed_interp : spline
             surface : None
      surface_interp : linear
            tx_depth : 500
   tx_directionality : [[-180.    0.]
                        [-170.    0.]
                        [-160.    0.]
                        [-150.    0.]
                        [-140.    0.]
                        [-130.    0.]
                        [-120.    0.]
                        [-110.    0.]
                        [-100.    0.]
                        [ -90.    0.]
                        [ -80.    0.]
                        [ -70.    0.]
                        [ -60.    0.]
                        [ -50.    0.]
                        [ -40.    0.]
                        [ -30.   20.]
                        [ -20.   20.]
                        [ -10.   20.]
                        [   0.   20.]
                        [  10.   20.]
                        [  20.   20.]
                        [  30.   20.]
                        [  40.    0.]
                        [  50.    0.]
                        [  60.    0.]
                        [  70.    0.]
                        [  80.    0.]
                        [  90.    0.]
                        [ 100.    0.]
                        [ 110.    0.]
                        [ 120.    0.]
                        [ 130.    0.]
                        [ 140.    0.]
                        [ 150.    0.]
                        [ 160.    0.]
                        [ 170.    0.]
                        [ 180.    0.]]
                type : 2D
In [ ]:
 
In [5]:
print(len(ir))

# Number of samples in normalized_tone
N = len(abs(ir)[0:int(0.1*100000)])

yf = fft(ir[0:int(0.1*100000)])
xf = fftfreq(N, 1 / 100000)

plt.plot(xf, np.abs(yf))
348763
In [6]:
#data Generation and Config

dataSize = 2000
m = 4
n = 2
samplingRate = 100000
carrierFreq = 27000
bitRate = 80
symbolRate = bitRate//n
txAmpDB = 40
rrcTaps = 6
#data Modulation

data =comm.random_data(dataSize, 2)
symbols = comm.bi2sym(data,m)
psk = comm.qam(m)
bb1 = comm.modulate(symbols,psk)
pb =  comm.upconvert(bb1, int(samplingRate/symbolRate),carrierFreq,samplingRate)

#Power Amplification

pb = pb * (10**(txAmpDB//20))

#Plotting

time = signal.time(pb,100000)
plt.plot(time,pb)
In [7]:
rxAmpDB = 0
#Received Signal
pbRx = np.convolve(pb,abs(ir)[0:int(0.1*100000)])
pbRx = pbRx[:len(pb)]
pbRx = comm.awgn(pbRx,20)

#Power Amplification

pbRx = pbRx * (10**(rxAmpDB//20))

#plotting
time = signal.time(pbRx,100000)
plt.plot(time,pbRx)
In [8]:
#Demodulating Signal
bbRx = comm.downconvert(pbRx, int(samplingRate/symbolRate),carrierFreq,samplingRate)
rxSymbols = comm.demodulate(bbRx,psk)
In [9]:
comm.ber(comm.sym2bi(rxSymbols,m),comm.sym2bi(symbols,m))
Out[9]:
0.0
In [12]:
plotBaseBandData(bb1,symbols)
In [13]:
plotBaseBandData(bbRx,symbols)
In [16]:
plotDiffData(300,2000,50)
Range: 300.0
0.0
Range: 334.6938775510204
0.0
Range: 369.38775510204084
0.0
Range: 404.0816326530612
0.0
Range: 438.7755102040816
0.0
Range: 473.46938775510205
0.159
Range: 508.1632653061224
0.105
Range: 542.8571428571429
0.062
Range: 577.5510204081633
0.159
Range: 612.2448979591836
0.0
Range: 646.9387755102041
0.0
Range: 681.6326530612245
0.1945
Range: 716.3265306122448
0.126
Range: 751.0204081632653
0.0
Range: 785.7142857142857
0.077
Range: 820.4081632653061
0.1775
Range: 855.1020408163265
0.0
Range: 889.7959183673469
0.0005
Range: 924.4897959183673
0.0
Range: 959.1836734693877
0.0035
Range: 993.8775510204082
0.1055
Range: 1028.5714285714284
0.0
Range: 1063.265306122449
0.0
Range: 1097.9591836734694
0.105
Range: 1132.6530612244896
0.146
Range: 1167.3469387755101
0.0
Range: 1202.0408163265306
0.055
Range: 1236.7346938775509
0.002
Range: 1271.4285714285713
0.2135
Range: 1306.1224489795918
0.0
Range: 1340.8163265306123
0.0
Range: 1375.5102040816325
0.0
Range: 1410.204081632653
0.2155
Range: 1444.8979591836735
0.0
Range: 1479.5918367346937
0.0095
Range: 1514.2857142857142
0.086
Range: 1548.9795918367347
0.0
Range: 1583.673469387755
0.2425
Range: 1618.3673469387754
0.0
Range: 1653.061224489796
0.2415
Range: 1687.7551020408164
0.064
Range: 1722.4489795918366
0.0
Range: 1757.142857142857
0.0
Range: 1791.8367346938776
0.2435
Range: 1826.5306122448978
0.2825
Range: 1861.2244897959183
0.306
Range: 1895.9183673469388
0.0545
Range: 1930.612244897959
0.082
Range: 1965.3061224489795
0.316
Range: 2000.0
0.0005
In [36]:
172,253 # ungroup
1065 # Exact
1106 # Shift
984,1025,1147,1187 # Scatter
Out[36]:
(172, 253, 984, 1025, 1065, 1106, 1147, 1187)
In [17]:
arr = [334, 404, 438,473, 612,646, 751, 855]
for i in arr:
    env = pm.create_env2d(frequency=27000,tx_depth=250,rx_depth=30,depth=1000,rx_range=i,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
    arrivals = pm.compute_arrivals(env)
    ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
    plt.plot(abs(ir)[0:int(0.1*100000)],fs = 100000)    
In [43]:
arr = [1350,1228,1228.3673469387757,1390,1431,1472,1512,1553]
for i in arr:
    env = pm.create_env2d(frequency=27000,tx_depth=60,rx_depth=45,depth=1000,rx_range=i,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
    arrivals = pm.compute_arrivals(env)
    ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
    plt.plot(abs(ir)[0:int(0.1*100000)],fs = 100000)    
In [42]:
1/80
Out[42]:
0.0125
In [ ]:
 
In [ ]:
 
In [18]:
#Getting Equalizer coefficients
trainSymbols = [0,1,2,3,2,1,0,2,3,1,2,0,3,1,3,0,0,1,2,3,2,1,0,2,3,1,2,0,3,1,3,0]
psk = comm.psk(4)
bb1 = comm.modulate(trainSymbols,psk)
#Upsampling
bb1 =  comm.upconvert(bb1, int(samplingRate/symbolRate),0,samplingRate)

#Power Amplification
bb1 = bb1 * (10**(txAmpDB//20))

#Channel Modelling
bbChn = Convolve(bb1,ir)
#modulating
pbChn =  comm.upconvert(bbChn,1,carrierFreq,samplingRate)
pbChn = comm.awgn(pbChn,20)
pb = comm.upconvert(bb1,1,carrierFreq,samplingRate)
#Plotting
time = signal.time(pbChn,samplingRate)
plt.plot(time,pbChn)

time = signal.time(pb,samplingRate)
plt.plot(time,pb)
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[18], line 12
      9 bb1 = bb1 * (10**(txAmpDB//20))
     11 #Channel Modelling
---> 12 bbChn = Convolve(bb1,ir)
     13 #modulating
     14 pbChn =  comm.upconvert(bbChn,1,carrierFreq,samplingRate)

Cell In[2], line 10, in Convolve(data1, data2)
      8 for i in range(0,len(data1)):
      9     for j in range(0,len(data2)):
---> 10         if i-j >=0:
     11             ans[i] = ans[i] + data1[i-j]*data2[j]
     12 return ans

KeyboardInterrupt: 
In [ ]:
#Demodulating Signal
bbRx = comm.downconvert(pbChn, int(samplingRate/symbolRate),carrierFreq,samplingRate)
bbTrueRx = comm.downconvert(pb, int(samplingRate/symbolRate),carrierFreq,samplingRate)
rxSymbols = comm.demodulate(bbTrueRx,psk)
In [ ]:
def getEqCoeff(bbhat,bb,ntap,stepfactor=0.01,convergance=0.001):
    bbRxReal = bbhat.real
    bbRxImag = bbhat.imag
    bbRxTrueReal = bb.real
    bbRxTrueImag = bb.imag
    eqCoeffReal = np.zeros(len(bbRxReal))
    eqCoeffImag = np.zeros(len(bbRxImag))
    
    while()
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [137]:
ir1 = np.zeros(100000,dtype=type(ir[0]))
In [129]:
ir1[0] =complex(1,1)
ir1[50000] = complex(0.01,0.05)
ir1[10000] = complex(0.2,0.05)
ir1[15000] = complex(0.01,0.05)
ir1[7000] = complex(0.3,0.5)
ir1[60000] = complex(0.01,0.05)
In [138]:
ir1[40000] = complex(1,1)
In [139]:
print(len(ir1))

# Number of samples in normalized_tone
N = len(ir1)

yf = fft(ir1)
xf = fftfreq(N, 1 / 100000)

plt.plot(xf, np.abs(yf))
100000
In [140]:
plt.plot(abs(ir1),fs = 100000)
In [110]:
x = complex(1,1)
In [111]:
x
Out[111]:
(1+1j)
In [112]:
type(x)
Out[112]:
complex
In [298]:
1/40
Out[298]:
0.025
In [10]:
len(beampattern[0])
Out[10]:
2
In [18]:
x = {0:20
In [20]:
 
Out[20]:
20
In [35]:
plt.plot(abs(ir),fs = 100000)
In [36]:
plt.plot(abs(ir)[0:10000],fs = 100000)
In [41]:
abs(ir)
[4.92515005e-02 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00
 0.00000000e+00 2.02418723e-05]
In [44]:
k = abs(ir)[0:5000]
In [45]:
for i in range(5000):
    if k[i] != abs(ir)[i]:
        print(i)
In [47]:
plt.plot(k,fs = 100000)
In [1]:
!jupyter nbconvert --to html equalizer.ipynb
[NbConvertApp] Converting notebook equalizer.ipynb to html
[NbConvertApp] Writing 11956280 bytes to equalizer.html
In [ ]: